import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class guiFun extends JFrame implements ActionListener {
	public static final int width=250;
	public static final int height=250;
	
	private JTextArea legend;
	
	private JLabel number1;
	private JLabel number2;
	private JLabel number3;
	private JLabel average;
	
	private JTextField number1Input;
	private JTextField number2Input;
	private JTextField number3Input;
	private JTextField output;
	
	private JButton run;
	private static final FlowLayout LAYOUT=new FlowLayout();
	
	public guiFun(){
		super();
		super.setSize(width, height);
		super.setTitle("Average Program");
		super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.setup();
	}
	public void setup(){
		legend=new JTextArea("Welcome to the Average  Program. This program computes the averages of three numbers.",2,19);
		legend.setLineWrap(true);
		legend.setWrapStyleWord(true);
		
		number1=new JLabel("Number");
		number2=new JLabel("Number");
		number3=new JLabel("Number");
		average=new JLabel("Average");
		
		number1Input=new JTextField(15);
		this.number1Input.addActionListener(this);
		
		number2Input=new JTextField(15);
		this.number2Input.addActionListener(this);
		
		number3Input=new JTextField(15);	
		this.number3Input.addActionListener(this);
		
		output=new JTextField(15);
		this.output.addActionListener(this);
	
		
	
		
		run = new JButton("Run");
		run.addActionListener(this);

		
		Container container=this.getContentPane();
		
		container.setLayout(LAYOUT);
		container.add(legend);
		container.add(number1);
		container.add(number1Input);
		container.add(number2);
		container.add(number2Input);
		container.add(number3);
		container.add(number3Input);
		container.add(average);
		container.add(output);
		container.add(run);
		
		
	}
	@Override
	public void actionPerformed(ActionEvent event) {
		// TODO Auto-generated method stub
		if(event.getActionCommand().equals("Run")){
		String input1=number1Input.getText();
		String input2=number2Input.getText();
		String input3=number3Input.getText();
		
		double Number1=Double.parseDouble(input1) ;
		double Number2=Double.parseDouble(input2);
		double Number3=Double.parseDouble(input3);
		
		double theAverage=(Number1+Number2+Number3)/3;
		String answer=String.valueOf(theAverage);
		
		this.output.setText(answer);
		}
		
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		guiFun window=new guiFun();
		window.setVisible(true);
	}

	

}
